﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Graph : MonoBehaviour
{
    [HideInInspector] private Transform pointPrefab;
    [Range(10, 500)] public int resolution = 10;

    private Vector3 position;
    private Transform[] points;
    private void Start()
    {
        points = new Transform[resolution];
        position.z = 0;
        Vector3 scale = Vector3.one / 5f;
        float cur = resolution / 2;
        for (int i = 0; i < resolution; i++)
        {
            Transform point = Instantiate(pointPrefab);
            position.x = i / 10f;
            position.y = Mathf.Sin(position.x) * 3;
            point.localPosition = position;
            points[i] = point;
            point.localScale = scale;
            point.SetParent(transform, false);

        }
    }

    private void Update()
    {
        for (int i = 0; i < resolution; i++)
        {
            Transform point = points[i];
            Vector3 position = point.position;
            position.y = Mathf.Sin(Mathf.PI * (position.x - Time.time));

            point.localPosition = position;
        }
    }



}
